﻿Public Class configuration
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Transparency
        My.Settings.TransparencyPercent = NumericTransparency.Value

        'Language pair
        If cbLanguagePair.CheckState = CheckState.Checked Then
            My.Settings.SaveLanguage = True
            Dim first As String
            Dim second As String
            first = goti.LanguageFrom.Text
            second = goti.LanguageTo.Text
            My.Settings.Languages = first & "&" & second
        Else
            My.Settings.SaveLanguage = False
            My.Settings.Languages = ""
        End If

        'Translator
       
        goti.LanguageFrom.SelectedIndex = 0 'TO DO: Ensure we actually have items in the drop-down before we try to select
                goti.LanguageTo.SelectedIndex = 1

                If My.Settings.Languages.Length > 0 Then
                    Dim parts() As String = Split(My.Settings.Languages, "&")
                    goti.SelectValueInCombo(goti.LanguageFrom, goti.LanguageFrom.DisplayMember, parts(0))
                    goti.SelectValueInCombo(goti.LanguageTo, goti.LanguageTo.DisplayMember, parts(1))
                End If
           


        My.Settings.Save()
        Me.Close()
    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericTransparency.ValueChanged
        ' Application opacity
        goti.Opacity = 1 - (NumericTransparency.Value / 100)
    End Sub


    Private Sub cbTranslator_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        BingTranslation.LoadBingLanguages()
    End Sub

    Private Sub configuration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NumericTransparency.Value = My.Settings.TransparencyPercent
        cbLanguagePair.Checked = My.Settings.SaveLanguage
        'Load speech path into textbox
        speechPathBox.Text = My.Settings.speechPath

    End Sub

    Private Sub btnSpeechPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpeechPath.Click
        'Show dialog to choose directory
        If browsePath.ShowDialog() = Windows.Forms.DialogResult.OK Then
            speechPathBox.Text = browsePath.SelectedPath
        End If
    End Sub

    Private Sub speechPath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles speechPathBox.TextChanged
        ' Save the speech path 
        My.Settings.speechPath = speechPathBox.Text
    End Sub

    Private Sub clearPath_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles clearPath.LinkClicked
        speechPathBox.Text = ""
    End Sub
End Class